<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">

    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
            <legend>请输入床位信息</legend>
        </fieldset>
        <form class="layui-form layui-form-pane" action="">

            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">患者id</label>
                    <div class="layui-input-inline">
                        <input type="text" id="pid" lay-verify="required" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">患者姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="pname" lay-verify="required" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">患者年龄</label>
                    <div class="layui-input-inline">
                        <input type="text" id="page" lay-verify="required" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">患者性别</label>
                    <div class="layui-input-inline">
                        <input type="text" id="psex" lay-verify="required" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">科室名称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="dename" lay-verify="required" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">床位信息</label>
                    <div class="layui-input-inline">
                        <input type="text" id="beds" lay-verify="required" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">入院时间</label>
                    <div class="layui-input-inline">
                        <input type="text" id="idate" lay-verify="required" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">预交款</label>
                    <div class="layui-input-inline">
                        <input type="text" id="deposit" lay-verify="required" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

            </div>


            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="saveBtn" style="width: 200px">添加</button>
            </div>
        </form>
    </div>
</div>

<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate,
            $ = layui.jquery,
            table = layui.table,
            layuimini = layui.layuimini;
        var userInfo = layui.data('userInfo');

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            var index = layer.alert("确定要提交吗?", {
                title: '确认提交'
            }, function () {

                $.ajax({
                    url:'http://localhost:8080/add/insertadd',
                    method:'post',
                    data:{
                        pid: $('#pid').val(),
                        pname: $('#pname').val(),
                        page: $('#page').val(),
                        psex: $('#psex').val(),
                        dename: $('#dename').val(),
                        beds: $('#beds').val(),
                        idate: $('#idate').val(),
                        deposit: $('#deposit').val(),
                        token: userInfo.token
                    },
                    async: true,
                    dataType:'JSON',
                    success:function(res){

                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                    }
                }) ;
                // 关闭弹出层
                layer.close(index);
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            });

            return false;

        });



    });
</script>

</body>
</html>